package Dao.impl;

import Dao.BookDao;
import db.DB;
import fake.domain.Book.Book;

/**
 * @ClassName:BookDaoImpl
 * @Author: 鹿建文
 * @Date: 2022/3/24  - 13:51
 * @Describe:
 */
public class BookDaoImpl implements BookDao {
    Book book = new Book();


    @Override
    public Book GetBookByISBN(String isbn) {
        for (Book book : DB.books) {
            if (book.getIsbn().equals(isbn)) {
                return book;
            }
        }
        return null;
    }

    @Override
    public Book GetBookBybname(String bname) {
        for (Book book : DB.books) {
            if (book.getBname().equals(bname)) {
                return book;
            }
        }
        return null;
    }

    @Override
    public Book GetBookByauthor(String author) {
        for (Book book : DB.books) {
            if (book.getAuthor().equals(author)) {
                return book;
            }

        }


        return null;
    }

    @Override
    public Book GetBookBypress(String press) {
        for (Book book : DB.books) {
            if (book.getPress().equals(press)) {
                return book;
            }

        }


        return null;
    }


    @Override
    public Book GetBookByprice(String price) {
        for (Book book : DB.books) {
            if (book.getPrice().equals(price)) {
                return book;
            }

        }


        return null;
    }

    @Override
    public boolean Updatebook(Book book) {
        if (book.getIsbn() == null) {
            return false;
        }
        for (Book book1 : DB.books) {
            if (book1.getIsbn().equals(book.getIsbn())){
                book1.setAuthor(book.getAuthor());
                book1.setBname(book.getBname());
                book1.setDate(book.getDate());
                book1.setPress(book.getPress());
                book1.setPrice(book.getPrice());
            }

        }

        return true;
    }

    @Override
    public boolean Addebook(Book book1) {
        if (book1.getIsbn() == null) {
            return false;
        }
//        if (book.getIsbn().equals(book1.getIsbn())) {
//            System.out.println("isbn已经有了");
//            return  false;
//        }

        DB.books.add(book1);
        Book.builder()
                .isbn(book1.getIsbn())
                .date(book1.getDate())
                .author(book1.getAuthor())
                .press(book1.getPress())
                .bname(book1.getBname())
                .build();






        return true;
    }
}